/**
  ******************************************************************************
  * @file           : RGB.cpp
  * @author         : admin
  * @brief          : None
  * @attention      : None
  * @date           : 2024/10/12
  ******************************************************************************
  */

#include "RGB.h"
DFRobot_NeoPixel pixels;
RGB::RGB()
{
    c[0] = 0, c[1] = 0, c[2] = 0;
    _brightness = 5;
    pixels.setBrightness((uint8_t)map(_brightness, 0, 9, 0, 255));
}

void RGB::write(int8_t index, uint8_t r, uint8_t g, uint8_t b)
{
    if (index >= 0 && index <= 2)
    {
        pixels.setRangeColor(index, index, pixels.rgbToColor(round(r), round(g), round(b)));
    }
    else
    {
        pixels.setRangeColor(0, 2, pixels.rgbToColor(round(r), round(g), round(b)));
    }
    delay(5);
}

void RGB::brightness(uint8_t b)
{
    if (_brightness == b)
        return;
    _brightness = max(min(b, 9), 0);
    pixels.setBrightness((uint8_t)map(_brightness, 0, 9, 0, 255));
}

uint8_t RGB::brightness()
{
    return _brightness;
}
RGB rgb;